package com.gitee.wsl.ext.list

import com.gitee.wsl.math.Math
import kotlin.math.min


fun <T: Comparable<T>> Math.compareLists(l1: List<T>, l2: List<T>): Int {
    val n1 = l1.size
    val n2 = l2.size
    for (i in 0 until min(n1, n2)) {
        val c = l1[i].compareTo(l2[i])
        if (c != 0) {
            return c
        }
    }
    return n1.compareTo(n2)
}

fun <T: Comparable<T>> List<T>.compareTo(other: List<T>): Int {
    return Math.compareLists(this, other)
}

fun <T> List<T>.equalsIgnoreOrder(other: List<T>) =
    this.size == other.size && this.toSet() == other.toSet()